Next | Prev | Up | Top | Contents | Index

Obtaining pc Sampling

Obtain pc sampling information by linking the desired source modules using the -p option and then executing the resulting program object, which generates raw profile data.

Use the procedure below to obtain pc sampling information. Also refer to Figure 4-1, which illustrates how pc sampling works.

  1. Compile the program using the appropriate compiler. For example, to compile a C program myprog.c:

    % cc -c myprog.c

  2. Link the object file created in Step 1.

    % cc -p -o myprog myprog.o

    Note: You must specify the -p profiling option during this step to obtain pc sampling information.

  3. Execute the profiled program (just as you would execute an unprofiled program).

    % myprog

    During execution, profiling data is saved in the file mon.out. You can run the program several times, altering the input data, to create multiple profile data files. You can also use the environment variable PROFDIR as explained in "Creating Multiple Profile Data Files."

  4. Run the profile formatting program prof.

    % prof -pcsample myprog mon.out

    prof extracts information from mon.out and prints it in an easily readable format. If mon.out exists, it is overwritten. Therefore, rename each mon.out to save its output.

Include or exclude information on specific procedures within your program by using the -only or -exclude profiler options (refer to Table 4-1).

Figure 4-1 : How pc Sampling Works


Next | Prev | Up | Top | Contents | Index